<template>
  <div class="user" style="padding: 0px;">
    <el-card>
      <el-button size="small" icon="Plus" @click="addClick" v-auth="'/sysuser/store/add'">新增地址</el-button>
      <el-table size="small" :data="tableData" border style="width: 100%;margin-top:10px;" v-loading="loading" stripe>
          <el-table-column prop="storeId" label="标识" width="80" align="center"></el-table-column>
          <el-table-column label="门牌" width="60" align="center">
            <template #default="scope">
              <img v-img-url="scope.row.logoImagePath" style="width:45px;height:45px;border-radius:5px;" />
            </template>
          </el-table-column>
          <el-table-column prop="storeName" label="门店名称" width="200"></el-table-column>
          <el-table-column prop="shopHours" label="营业时间" align="center" width="100"></el-table-column>
          <el-table-column prop="linkman" label="联系人" align="center" width="100"></el-table-column>
          <el-table-column prop="phone" label="联系电话" align="center" width="120"></el-table-column>
          <el-table-column prop="address" label="门店地址"></el-table-column>
          <el-table-column prop="isCheck" label="自提核销" align="center" width="100">
            <template #default="scope">
              <span :class="{ green: scope.row.isCheck == 1, gray: scope.row.isCheck == 0,}">{{ scope.row.isCheckText }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="门店状态" align="center" width="100">
            <template #default="scope">
              <span :class="{ green: scope.row.status == 1, gray: scope.row.status == 0,}">{{ scope.row.statusText }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="创建时间" align="center" width="150"></el-table-column>
          <el-table-column label="操作" align="center" width="180">
            <template #default="scope">
              <el-button @click="editClick(scope.row)" type="text" size="small" v-auth="'/sysuser/store/edit'" icon="Edit">编辑</el-button>
              <el-button @click="deleteClick(scope.row)" type="text" size="small" v-auth="'/sysuser/store/delete'" icon="Delete" style="color:red;">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination style="float:right;margin-top:10px;margin-bottom:10px;" @size-change="handleSizeChange" @current-change="handleCurrentChange" background :current-page="curPage" :page-size="pageSize" layout="total, prev, pager, next, jumper" :total="totalDataNumber"></el-pagination>
    </el-card>
  </div>
</template>

<script>
import StoreApi from "@/api/store.js";
import { defaultPageSize } from '@/utils/table.js'
export default {
  components: {},
  inject: ["reload"],
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 10,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        user: "",
        region: "",
      },
      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      userModel: {},
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },

    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = {};
      self.loading =true 
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      StoreApi.shoplist(Params, true)
        .then((res) => {
          self.loading = false;
          self.tableData = res.data.records;
          self.totalDataNumber = res.data.total;
        })
        .catch((error) => {
          self.loading = false;
         });
    },

    /*打开添加*/
    addClick() {
      this.$router.push("/sysuser/store/add");
    },

    /*打开编辑*/
    editClick(row) {
      let self = this;
      let params = row.storeId;
      this.$router.push({
        path: "/sysuser/store/edit",
        // name: 'mallList',
        query: {
          storeId: params,
        },
      });
    },

    /*删除*/
    deleteClick(row) {
      let self = this;
      ElMessageBox.confirm("此操作将永久删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          StoreApi.deleteShop(
            {
              storeId: row.storeId,
            },
            true
          )
            .then((data) => {
              ElMessage({
                message: "恭喜你，门店删除成功",
                type: "success",
              });
              self.getTableList();
            })
            .catch((error) => { });
        })
        .catch(() => { });
    },
  },
};
</script>

<style></style>
